<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-11-08 11:04:02
 * @LastEditors: charles
 * @LastEditTime: 2021-11-08 11:29:23
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数组件</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
  <div id="app"></div>
  <script type="text/babel">
    // 1. 组件 - 函数组件、类组件
    class App extends React.Component {
      constructor(props){
        super(props);
        // 状态 - vue data
        this.state = {
          num:1
        }
      }
      // 生命周期
      componentDidMount(){
        setInterval(() => {
          this.setState({
            num:++this.state.num
          })
        }, 2000);
      }



      render(){
        let msg = "hello react"
        return <div>{msg}, {this.state.num}</div>;
      }
    }

    // 2. 渲染到页面
    ReactDOM.render(<App/>, document.getElementById('app'));


  </script>
  
</body>
</html>
